#include "junix.h"

//#include <boost/bind.hpp>

using namespace std;

struct A
{
	int v_;
	A(int i):v_(i){}
	int operator()()
	{
		return v_++;
	}
};

void minus2(int & i)
{
	i -= 2;
}

struct Plus
{
	int v_;
	Plus(int n):v_(n){ }
	void operator()(int& i)
	{
		i += v_;
	}
};

int main(int argc, char **argv)
{
	vector<int> vi(20);
	generate(vi.begin(),vi.end(),rand);
	copy(vi.begin(),
			vi.end(),
			ostream_iterator<int>(cout," "));
	cout<<endl;
	
	generate(vi.begin(),vi.end(),
			boost::bind(std::modulus<int>(),A(3)(),15));
	copy(vi.begin(),vi.end(),
			ostream_iterator<int>(cout," "));
	cout<<endl;

	generate(vi.begin(),vi.end(),A(3));
	copy(vi.begin(),vi.end(),
			ostream_iterator<int>(cout," "));
	cout<<endl;

	for_each(vi.begin(),vi.end(),minus2);
	copy(vi.begin(),vi.end(),
			ostream_iterator<int>(cout," "));
	cout<<endl;

	for_each(vi.begin(),vi.end(),ptr_fun(minus2));
	copy(vi.begin(),vi.end(),
			ostream_iterator<int>(cout," "));
	cout<<endl;

	for_each(vi.begin(),vi.end(),Plus(2));
	copy(vi.begin(),vi.end(),
			ostream_iterator<int>(cout," "));
	cout<<endl;
	return 0;
}
